package leetcode;

/**
 * @program: datastructureandalogorithm
 * @description:
 * @author: hmx
 * @create: 2021-11-28 14:40
 **/
public class LeetCode5940 {

    public int minimumDeletions(int[] nums) {
        int min = Integer.MAX_VALUE;
        int minIndex = 0;
        int max = Integer.MIN_VALUE;
        int maxIndex = 0;
        int len = nums.length;
        for (int i = 0; i < len; i++) {
            if (nums[i] < min) {
                min = nums[i];
                minIndex = i;
            }
            if (nums[i] > max) {
                max = nums[i];
                maxIndex = i;
            }
        }

        int a;
        int b;
        if (minIndex <= maxIndex) {
            a = minIndex;
            b = maxIndex;
        } else {
            b = minIndex;
            a = maxIndex;
        }
        return Math.min(b + 1, Math.min(len - a, a + 1 + len - b));
    }

}
